/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.core.service;

import info.peigen.hotpot.business.customer.facade.PartnerServiceFacade;
import info.peigen.hotpot.business.customer.facade.order.partner.PartnerApplyPermissionOrder;
import info.peigen.hotpot.business.customer.facade.order.partner.PartnerApplyTechOrder;
import info.peigen.hotpot.business.customer.facade.order.partner.PartnerCreateOrder;
import info.peigen.hotpot.business.customer.facade.result.partner.PartnerApplyPermissionResult;
import info.peigen.hotpot.business.customer.facade.result.partner.PartnerApplyTechResult;
import info.peigen.hotpot.business.customer.facade.result.partner.PartnerCreateResult;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import org.noear.solon.annotation.Component;

/**
 * <b>(PartnerService)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/7/29
 */
@Component
public class PartnerService extends AbstractPartnerService implements PartnerServiceFacade {
    @Override
    public PartnerCreateResult register(PartnerCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new PartnerCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(partnerCreateProcessor, partnerCreateSelfAccountProcessor, partnerCreateIntermediateAccountProcessor, partnerApplyPermissionProcessor, partnerApplyTechProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(storePartnerProcessor, partnerCreateResultProcessor);
            }

        });
        return (PartnerCreateResult) serviceContext.getResult();
    }

    @Override
    public PartnerApplyPermissionResult applyPermission(PartnerApplyPermissionOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new PartnerApplyPermissionResult()).build();

        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(activePartnerByLockProcessor, partnerApplyPermissionProcessor, partnerApplyPermissionResultProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(storePartnerProcessor);
            }

        });
        return (PartnerApplyPermissionResult) serviceContext.getResult();
    }

    @Override
    public PartnerApplyTechResult applyTech(PartnerApplyTechOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new PartnerApplyTechResult()).build();

        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(activePartnerByLockProcessor, partnerApplyTechProcessor, partnerApplyTechResultProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(storePartnerProcessor);
            }

        });
        return (PartnerApplyTechResult) serviceContext.getResult();
    }


}
